package com.epam.mentoring.music.ui;

import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;

public class Navigation {
    public static WebDriver driver;

    //Home Page elements
    public void clickLinkHome(){
        clickLink("Home");
    }

    //Artists Page elements
    public void clickLinkArtists(){
        clickLink("Artists");
    }

    //About Page elements
    public void clickLinkAbout(){
        clickLink("About");
    }

    //Tracks Page elements
    public void clickLinkTracks(){
        clickLink("Tracks");
    }

    //Methods
    private void clickLink(String LinkText) {
        WebElement webLink = driver.findElement(By.linkText(LinkText));
        webLink.click();
    }

    @BeforeClass
    public static void setUp() throws Exception{
        String operationSystem = System.getProperty("os.name");
        System.out.println("OS.Name " + operationSystem);
        if (operationSystem.startsWith("Windows")){
            System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
        }   else if(operationSystem.startsWith("Linux")){
            System.setProperty("webdriver.chrome.driver", "chromedriver");
        }
        driver = new ChromeDriver();
        driver.get("http://localhost:4567/");
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(scrFile, new File("src/main/resources/com/epam/mentoring/music/ui/scr_main_page.png"));
    }

    @AfterClass
    public static void tearDown() throws Exception{
        driver.quit();
    }


}
